package com.zt.controller;

import com.zt.dto.GenerateRequest;
import com.zt.service.AliyunAIService;
import com.zt.service.FileStorageService;
import io.minio.MinioClient;
import io.minio.errors.MinioException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * @author 86191
 * @version 1.0
 * @Date 2025/4/1610:00
 */
@RestController
@RequestMapping("/aipaizhao")
public class AipaizhaoController {
    private static final String MINIO_ENDPOINT = "http://114.55.56.174:19000";
    private static final String MINIO_ACCESS_KEY = "minioadmin";
    private static final String MINIO_SECRET_KEY = "minioadmin";
    private static final String BUCKET_NAME = "house";

    @Autowired
    private AliyunAIService aliyunAIService;

    @Autowired
    private FileStorageService fileStorageService;
    @PostMapping("/generateImageFromText")
    public String generateImageFromText(@RequestBody GenerateRequest generateRequest) throws Exception {
        System.err.println(generateRequest);
        String s = aliyunAIService.generateImageFromText(generateRequest.prompt, generateRequest.roomImageUrl);
        return s;
    }

//    将图片上传到minio里面转换为base64编码
//    @GetMapping("/generateImageFromImage")
//    public String generateImageFromImage(String image) throws Exception {
//        try {
//            // 创建MinIO客户端
//            MinioClient minioClient = MinioClient.builder()
//                    .endpoint(MINIO_ENDPOINT)
//                    .credentials(MINIO_ACCESS_KEY, MINIO_SECRET_KEY)
//                    .build();
//
//            // 检查存储桶是否存在，如果不存在则创建
//            boolean isBucketExists = minioClient.bucketExists(BUCKET_NAME);
//            if (!isBucketExists) {
//                minioClient.makeBucket(BUCKET_NAME);
//            }
//
//            // 上传图片文件
//            String objectName = "example.jpg"; // 上传到MinIO的文件名
//            String filePath = "path/to/your/image.jpg"; // 本地图片路径
//
//            minioClient.uploadObject(
//                    io.minio.messages.UploadObjectArgs.builder()
//                            .bucket(BUCKET_NAME)
//                            .object(objectName)
//                            .filename(filePath)
//                            .build()
//            );
//
//            System.out.println("图片上传成功: " + objectName);
//
//        } catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
//            System.out.println("Error occurred: " + e);
//        }
//
//    }
}
